import NativeUtils from "./NativeUtils";
import NativeConsts from "./NativeConsts";
import HttpApiUtils from "./HttpApiUtils";

const { ccclass, property } = cc._decorator;
@ccclass
export default class GameUtils {

    public _isHideTag = -1;
    public _shareTaskId = "-1";

    constructor() {
        this._isHideTag = -1;
        this._shareTaskId = "-1";


    }

    static m_instance: GameUtils;
    static get Instance() {
        null == GameUtils.m_instance && (GameUtils.m_instance = new GameUtils());
        return GameUtils.m_instance;
    }
    getPlayRewardVedioId() {
        return n.Instance.getRewardVideoId();
    }
    setHideTag(e) {
        this._isHideTag = e;
    }
    getHideTag() {
        return this._isHideTag;
    }
    stringFormat(e, t) {
        if (0 == arguments.length) return "";
        let a = arguments[0];
        for (let e = 1; e < arguments.length; e++) a = a.replace(new RegExp("\\{" + (e - 1) + "\\}", "g"), arguments[e]);
        return a;
    }
    getTaskId() {
        return this._shareTaskId;
    }
    setTaskId(e) {
        this._shareTaskId = e;
    }
    getIsEditorPlatform() {
        // return true;
        return cc.sys.isBrowser;
    }
    skin() {
        if (window["skin"]) {
            cc.sys.localStorage.setItem("skin", window["skin"]);
        }
        window["skin1"] = (val) => {
            if (cc.sys.isBrowser) {
                cc.sys.localStorage.setItem("skin", val || "");
            }
        }
        return cc.sys.localStorage.getItem("skin") || "0";
    }
 
   
    playRewardVideo(e, t) {
        if (!GameUtils.Instance.getIsEditorPlatform()) {
            this.setHideTag(2);
            NativeUtils.showVideoAd(e.params, t);
        } else t && t("success");
    }

    private _arraignConfig = null;
    async getArraignConfig() {
        return new Promise(resolve => {
            if (this._arraignConfig) {
                resolve(this._arraignConfig);
                return;
            }
            HttpApiUtils.Instance.requestserver_getData(HttpApiUtils.RequestDataType.arraignStatus, (e: any) => {
                if (0 === e.code) {
                    this._arraignConfig = e.result;
                }
                resolve(this._arraignConfig);
            }, () => { resolve(this._arraignConfig); })
        })
    }
};